﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ChuongtrinhQLHSTHPT
{
    public partial class Dsachgiaovienchunhiem : Form
    {
        public Dsachgiaovienchunhiem()
        {
            InitializeComponent();
        }
        public int MALOP;
        private void btnupdate_Click(object sender, EventArgs e)
        {
            MALOP = Int32.Parse(txtMalop.Text);
            int MAGV = Int32.Parse(txtMagv.Text);
            bool isUpdate = new Connectionclass().UpdateGVCN(MALOP,MAGV);
            if (isUpdate == true)
            {
                dataGridView1.DataSource = new Connectionclass().Loaddsgvcn();
                MessageBox.Show("Cập nhật thành công !");
                txtMalop.Text = "";
                txtMagv.Text = "";
            }
            else
            {
                MessageBox.Show("Cập nhật không thành công!");
            }
        }

        private void Dsachgiaovien_Load(object sender, EventArgs e)
        {
            Connectionclass con = new Connectionclass();
            dataGridView1.DataSource = con.Loaddsgvcn();
            dataGridView1.Columns[0].Visible = false;
            txtMalop.Hide();
            
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {

                MALOP = Int32.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
                int MAGV = Int32.Parse(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString());
                txtMalop.Text = MALOP.ToString();
                txtMagv.Text = MAGV.ToString();
            }
            catch
            {
                MessageBox.Show("Bạn chưa chọn đúng bản ghi !");
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
    }
}
